# This is the Java language backend for awib
# Please refer to the documentation in the full source code distribution
# of awib for additional details

% 23(0) *8 (code) 0 M m
# print Java header
++[-<+<++++++<+++<+++++++++++++<++++++++++++<+++++++++<++++++++++<++++++
+++++<++++<+++++++<++++++++<++<+++++>>>>>>>>>>>>>]<<<<<<<+++++.<-.+++.-.
+++.++.>>>>>++.<<<<+.>+++++++.>--.<.<<<++++++.>>-.++++++.<<.<+++.>>>-.++
.<+.-.<<<+++.>>>.--.>>++++.----.<---.>>>>>-.>.<<<<<<----.++++.+++.-.<.++
.>>>>>.<<<<-----.>.>.<.<<<.>>-.++++++.<<.<<----.>>>+.-.>+.<+.-.<<<++++.>
>>.--.>>++++.----.<---.>>>>>.>.<<<<<<----.++++.+++.-.<.++.>>>>>.<<<<----
-.>.>.<.<<<.>>-.++++++.<<.<.<----.>----.>>++++.>>++.++.<+.>>--.<++++.<-.
-.>>>>>.>..<<<<----.+++++.<-------.<--.---.>+.>>>.<<<.<+++.>--.>--..>>.>
+++++++.<<<<+++++.>>>.<-------.>>>.<<....<<<----.<<+.>>>+.<+++.---------
-.++.>>>.<<<<+.>>>>>-------.>.<<....<<<<----.+++++.>>.>>.<<----.>>>.>.<<
....<<<<<<<++++.>>>.>>.+++++.-.<<<<<<++++.>>>>>>.--.<++++++++.----.<-.>>
>>.<<<<----.>>>>>.>.<<....<<<<<<<<----.>>>----.-.----.+++++.-.<<<++++.>>
>.--.>----.>.>-----.>>.<<++.>>>.>..<<....<<+.+++++.<+.<+++++++.---.>+.>>
>.>+++++++.<<<<+++.<<<------.<.>>----.++.>>>.-.<<<<<<.>>>>>>.--.<-.----.
<++++.>>>>.<<<<----.<<++++.>>>>>>.<<<<<<<<----.>>>+++++.-.----.+++++.-.<
<<++++.>>>.--.>----.>.>-----.>>.<<++.<<<<---.>>>>>>.<.>>>.<<........<<--
.>>>-----.<<<+.<<.<+++++.>>>>>.<<<+.>>--.-----.<<<.>-------.>>>>-------.
-..--.++.<<<<++.>>>>++++++.>.<<........<<++.>>>++.-------------.++++++++
+++.>.-.<<<.<<<+++.+.>>>-.<<<<<+++++.>>.>>>>>++.<<<<<.>>>>>--.>+.-.<<<+.
<<<-.+.>>>-.<<<<<.>>>>-.>>>++.<<<.>>>--.>+.<<....<++++++++++.>>>..<<....
<<+.+++++.<+++++.<+++.---.>+.>>>.<<+.-------.<<.>+.>>>.<<+++.+++.-------
.>>.++++++++.+.---------.<--.>>>.<<........<-------.<<<-.+.>>>-.<<<<<.>>
>-----.<<<++.--------.+.>>>>>>>.>.<<....<++++++++++.>>>..<<....<<++.++++
+.<+++.<+++.---.>+.>>>.<<--.+.<--.>.<<.>++.>>>.<<++.-------.<<.>+.>>>.<<
--.<---.<.>>+.<<<<-.<<.>>>---.--.>.>>.<<--.>------.++.>>>.<<<++++.<<.>.<
+.<+.>>>>>>.<--.>>>.-.<<<<.<<--.<++++.>>>>>.>+++++++.<<<<<+.<<-.<<.>>>++
.------.+.>-.>>-.<<<<++++++.>>++++.>>+.<<<<--.<<.>>>+++++.------.+.>----
.>>-.<<<<++.>>>>++.<<<+.-.<-----.+++++.>--.+++.>>>-.>>++++++++.+.>------
-.>+.<<---------....<++.>>>..<<....<<++.++.<<++++.<+.>>.>++.<++++.>>>.<<
++.-------.<<.>-.>>>.<<+++.>>++++++++.+.---------.<--.>>>.-.<<<<++.--.>-
-.>.<++.>>>+.-.<<....<<<<.<<.>>>>.<+.----.+++.<<<------.>>++++.<<++++.>>
+++.<<.+++++.--------.>>>>>>>.>+.-.<<<++.>.<<<-.--.>++.<++.+++++.>>>.<<<
<<<-.<.<----.>----.>>++.>>-----.++.<.>>.<++++.<-.-.>>>>.<<<----.<<<+.>>>
>>>.<--.++.>>>+.<<....<.>>>..<<....<<----.++.<++++.<<--.>>--------.>++.<
++++.>>>.<<++.<<+.>++++.-----.>>>.<<+.<<<<-.+.>>>>>>.<--.>>>.-.<<<<---.-
-.>--.>.<++.>>>+.-.<<....<<<<.<<+++++.>+.>>>.<+++++.>++.<----.<<<------.
>>--.>----------.<+++.>++.<<<+.>>>>>>>.>+.-.<<<++.>.<<<++++++.--.>.<++.+
++++.>>>.<<<<<<-.<++++.<.>----.>>+.>>-----.++.<.>>.<++++.<-.-.>>>>.<<<--
--.<<<+.>>>>>>.<--.++.>>>+.<<....<.>>>..<<....<<----.++.<++++.<<--.>>---
-----.>++.<++++.>>>.<<++.<<+.>++++.-----.>>>.<<<-----.<<<<<<<--.>>>>-.+.
>>>>>>.<--.>>>.[<]>[[-]>]
% 23(0) *0 (code) 0 M m

++++++++++++++++[-<++++++++++++++++>]<-[-<<<<<<<<<<<<<<<+<+>>>>>>>>>>>>>>>>]
<<<<<<<<<<<<<<<<<<+<+>>>>>>>>>>>>>>>>>>>>
% 4(0) 1 0 255 255 15(0) *0 (code) 0 M m

>[<+>
% ::: (stack)  0 1:::1 0 c d 15(0) 1 *P i (code) 0 M m
% (where c and d form a two cell counter
%        P(i) is the next op code)

# the stack segment is a sequence of adjacent C and D; these values
# are previous values of the cd counter that have been pushed to stack
# on OPEN; they are in turn popped on CLOSE


-[-[-[-[-[-[-[-[-[-[-[-[[-]

<[
# RMUL2
% ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
+++++[->+++++++++++++++<]>+++.-[--<+>]<---.-[-->+++<]>--.------[-<++>]<-.-
-----------------.+[---->+++++<]>---.+++[-----<++++>]<+.-[-->+<]>----.[-]
<<<+<<+>>>>
% ::: (stack)  0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# RMUL1
% ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
--[----->++<]>-.[-]<<<+>>
% ::: (stack)  0 1:::1 0 c d 11(0) 0 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# LMUL2
% ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
+++++[->+++++++++++++++<]>+++.-[--<+>]<---.-[-->+++<]>--.------[-<++>]<-.-
-----------------.+[---->+++++<]>---.+++[-----<++++>]<+.-[-->+<]>----.[-]
<<<+<<+>>>>
% ::: (stack)  0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# LMUL1
% ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
--[----->++<]>+.[-]<
<<+>>
% ::: (stack)  0 1:::1 0 c d 11(0) 0 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# SET
% ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++[->++++++<]>[-<++++<+++<+<++>>>>]<-----------.<+.>+++.<++.
<<+.>++++++++++.>+++++.>+++++++++.-----.<+++.<+.>>[[-]<]+>>+>>
% ::: (stack)  0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]>]

<[-
# CLOSE
% ::: (stack)  0 1:::1 0 c d 15(0) *0 0 0 (code) 0 M m
# output: '    }\n\n    private void '
+++++++++++++++++++++++++[-<+<+++++<++++<++<+++>>>>>]<+++++++....<.
>>++++++++++..<....<-------------.++.<+++++.>++++.<--------.>--.<++++
.>>.<++.-------.<++++.-----.>>.>[[-]<]<<<<<<<<<<<<
% ::: (stack)  0 1:::1 *0 c d 15(0) 0 0 0 (code) 0 M m

# fetch xy from top of stack
<[<]<[->>[>]>>>>+<<<<<[<]<]<[->>>[>]>>>>>+<<<<<<[<]<<]>+>+[>]
% ::: (stack)  0 1:::1 *0 c d  0 y x 12(0) 0 0 0 (code) 0 M m

# output: '_x_y'
>>>>>[
>++++++++[->++++++++++++<]>-.[-]
# itoa
++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
>++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
>++++++[-<++++++++>]<<[>[-<+<+>>]<.[-]<.[-]>]
<[>>[-<<+>>]<<.[-]]>>[-]<<++++++[-<++++++++>]<.[-]<
]
% ::: (stack)  0 1:::1 0 c d *0 14(0) 0 0 0 (code) 0 M m

# output: '() {'
+++++++++++++++++++++++++++++++++++++++++[->+++>+>++<<<]
>>-.+.---------.<.<++++++++++.[[-]>]>>>>>>>>>>>
% ::: (stack)  0 1:::1 0 c d 15(0) *0 0 0 (code) 0 M m
]>]

<[-
# OPEN
% ::: (stack)  0 1:::1 0 c d 15(0) *0 0 0 (code) 0 M m

# build ef = dec(cd)
<<<<<<<<<<<<<<<<[[->>+>>>>>>>>+<<<<<<<<<<]<]
>>>>>+<-[>-]>[>]<[+++++++++++++++[-<++++++++++++++++>]<-<->>]<
% ::: (stack)  0 1:::1 0 0 0 e *f 6(0) c d 5(0) *0 0 0 (code) 0 M m

# push a copy of ef to stack
<<<<<[<]>->->[>]>>>
[-<<<<[<]<<+>>>[>]>>>>>>>>>+<<<<<<]>
[-<<<<<[<]<+>>[>]>>>>>>>>>>+<<<<<<]>>>>>>>>
% ::: (stack ef)  0 1:::1 9(0) e f c *d 5(0) 0 0 0 (code) 0 M m

# construct decimal representations of e f c and d
[
% 0 (counters) *n 5(0) 0 0 0
% (where n is the rightmost counter)
# itoa
% (counters) *n 5(0) 0 0 0
>>++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
>++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
>++++++[-<++++++++>]<<[>[-<+<+>>]<:[->>>>+<<<<]<:[->>>>>>+<<<<<<]>]
<[>>[-<<+>>]<<[->>>>>>+<<<<<<]]>>[-]<<++++++[-<++++++++>]<[->>>>>>>>+<<<<<<<<]
% (counters) *0 5(0) n2 n1 n0
% (where n2n1n0 is n in base 10
%        ni is 0 if not significant)
# move down remaining counters to make room for next base 10 rep
<[<]>[[-<<+>>]>]<<<
]
% ::: (stack)  0 1:::1 *0 8(0) e2 e1 e0 f2 f1 f0 c2 c1 c0 *d2 d1 d0 (code) 0 M m

# output: '        while(m{p}!=0){_'
# but with brackets instead of braces
++++++++++++++++++++++++++++++[->++>+>++++>+++<<<<]>>++........>-.
---------------.+.+++.-------.<++++++++.>++++++++.>+.<+++.>++.
<<-------.<+.-------------.-------.>>+++++++++++.>++.>
% 0 41 33 123 95 *0 0 0 0 e2 e1 e0 f2 f1 f0 c2 c1 c0 d2 d1 d0

# output: '_c_d();}'
# replace c and d with the corresponding decimal representation
>>>>>>>>>
>[.[-<<<<<<<<<+>>>>>>>>>]]>[.[-<<<<<<<<<+>>>>>>>>>]]>[.[-<<<<<<<<<+>>>>>>>>>]]
<<<<<<<<<<<<<.>>>>>>>>>>>>>
>[.[-<<<+>>>]]>[.[-<<<+>>>]]>[.[-<<<+>>>]]
<<<<<<<<<<<<<<<<<<<-.+.++++++++++++++++++.------------------>>++.
<<<++++++++++.>->-
% 10 40 *32 125 95 0 c2 c1 c0 e2 e1 e0 f2 f1 f0 d2 d1 d0 0 0 0

# output: '        _e_f();\n    }\n\n    private void _c_d'
# again with e f c and d replaced by their base 10 reps
........>>.>>>>
>[.[->>>>>>>>>+<<<<<<<<<]]
>[.[->>>>>>>>>+<<<<<<<<<]]
>[.[->>>>>>>>>+<<<<<<<<<]]
<<<<<<<.>>>>>>>
>[.[-<<<+>>>]]
>[.[-<<<+>>>]]
>[.[-<<<+>>>]]
% 10 40 32 125 95 0 c2 c1 c0 f2 f1 f0 0 0 *0 d2 d1 d0 e2 e1 e0
<<<<<<<<<
<<<<.+.++++++++++++++++++.<.>>....>.<<<..>>....>-------------.++.---------.
+++++++++++++.>++.<--.>++++.<<.>++.-------.>++++.-----.<<.>>-----.<<<<
% *10 59 32 111 95 0 c2 c1 c0 f2 f1 f0 0 0 0 d2 d1 d0 e2 e1 e0
>>>>>
>[.[-]]>[.[-]]>[.[-]]
<<<<.>>>>>>>>>>
>[.[-]]>[.[-]]>[.[-]]
% 10 59 32 111 95 0 0 0 0 f2 f1 f0 0 0 0 0 0 *0 e2 e1 e0

# restore ef
>[[-<+>]++++++[-<-------->]]
>[[-<+>]++++++[-<-------->]]
>[[-<+>]++++++[-<-------->]]
<<[->++++++++++<]
<[->++++++++++[->++++++++++<]<]
<<<<<
<[[->+<]++++++[->--------<]]
<[[->+<]++++++[->--------<]]
<[[->+<]++++++[->--------<]]
>>[->++++++++++<]<[->++++++++++[->++++++++++<]<]
% 10 59 32 111 95 0 0 0 0 0 *0 0 f 0 0 0 0 0 0 e 0

# output: '() {'
# and move ef into position
<<<<<<<<++++++++.+.---------.>++++++++++++.<<<.
[[-]>]
>>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]
>>>>>>>[-<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>]
% 0 e f 15(0) 0 *0 0

# leave behind gh = dec(dec(cd)) = dec(ef)
<<<<<<<<<<<<<<<<+<-[>-]>[>]<[+++++++++++++++[-<++++++++++++++++>]<-<->>]
>>>>>>>>>>>>>>>
% ::: (stack) 0 1:::1 0 g h 15(0) *0 0 0 (code) 0 M m
]>]

<[
# RIGHT
% ::: (stack)  0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->+++++++++++++++++++<]>--.--[-----<++>]<-.-[-->+++<]>--.[-]<
<<+<<+>>>>
% ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# LEFT
% ::: (stack)  0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->+++++++++++++++++++<]>--.--[-----<++>]<+.[--->++++<]>+.[-]<
<<+<<+>>>>
% ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# OUTPUT
% ::: (stack)  0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->++++++++++++++++++++<]>-.+[---<+>]<.+.[-]
<<<<+>>>>
% ::: (stack) 0 1:::1 0 c d 11(0) 1 0 0 0 *0 0 i (code) 0 M m
]>]

<[
# SUB
% ::: (stack)  0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
+++[----->++++<]>+.-[--<+>]<-.[--->++++<]>+.[-]<
<<+<<+>>>>
% ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]>]

<[
# INPUT
% ::: (stack)  0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->+++++++++++++++++++<]>.[---<+>]<++.+.[-]
<<<<+>>>>
% ::: (stack) 0 1:::1 0 c d 11(0) 1 0 0 0 *0 0 i (code) 0 M m
]>]

<[
# ADD
% ::: (stack)  0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
+++[----->++++<]>+.-[--<+>]<---.-[-->+++<]>--.[-]<
<<+<<+>>>>
% ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
]

# optionally append ; and/or itoa(i)
% ::: (stack)  0 1:::1 0 c d 11(0) b 0 a 0 *0 0 i (code) 0 M m
% (where a==1 iff i should be output
%        b==1 iff ';\n' should be output)
<<[->>
% ::: b 0 0 0 *0 0 i (code) 0 M m
# itoa
++++++++++>>[-<<-<+>[<-]<[<]>[->++++++++++>+<<]>>>]++++++++++<<[->>-<<]
<++++++++++>>[-<<-<+>[<-]<[<]>[->++++++++++>+<<]>>>]++++++++++<<[->>-<<]
<++++++[->++++++++<]>>[<[->+>+<<]>.[-]>.[-]<]
>[<<[->>+<<]>>.[-]]<<[-]>>++++++[->++++++++<]>.[-]
<<<<]
<<[+++++[->++++++++++<]>-.[-]++++++++++.[-]<]>>>>>>[-]
% ::: (stack)  0 1:::1 0 c d 15(0) 0 0 *0 (code) 0 M m

# copy up cd; extend the 1 sled; process next operation
<<<<<<<<<<<<<<<<<<[->>+<<]<[->>+<<]+<+>>>>>>>>>>>>>>>>>>>>
>]

% ::: 0 0 0 *0 M m

# footer
>[-]>[-]
++++++++++++++++++++[->+++++++>+++>+>++++>++>++++++>+++++<<<<<<<]+++++++
++.>>>>+++.>>+.------.+.>+.<-------.<++++++.>++.++++++.-.<.>>+.++++++.<+
.--.>----.<<------.+.<<<-.<<+.-.>---------------.<+.>.<.
[[-]>]

% ::: 0 0 *0 0 0
